package com.example.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BankController {
    @PostMapping("/transfer")
    public String transfer(@RequestParam String to, @RequestParam int amount, HttpSession session) {
        Object user = session.getAttribute("user");
        if (user == null) {
            return "未登录，转账失败";
        }
        return "用户 " + user + " 成功转账 " + amount + " 元给 " + to;
    }

    @GetMapping("/login")
    public String login(HttpSession session) {
        session.setAttribute("user", "Alice");
        return "登录成功，欢迎 Alice";
    }
}
